﻿using System.Globalization;
using System.Threading;
using System.Web.Http.Controllers;
using System.Web.Mvc;
using Website.Interfaces;

namespace Website.Infrastructure
{
    public class LanguageFilterAttribute : ActionFilterAttribute
    {
        private ICultureManager _cultureManager;

        public LanguageFilterAttribute(ICultureManager cultureManager)
        {
            _cultureManager = cultureManager;
        }

        public override void OnActionExecuting(ActionExecutingContext context)
        {
            if (context.HttpContext.Request.Url.Host.EndsWith(".nl"))
            {
                _cultureManager.SetCulture("nl");
            }
            base.OnActionExecuting(context);
        }
    }
}